
var ie55 = /MSIE ((5\.[56789])|([6789]))/.test( navigator.userAgent ) &&
			navigator.platform == "Win32";

if ( !ie55 ) {
	window.onerror = function () {
		return true;
	};
}

function writeNotSupported() {
	if ( !ie55 ) {
		document.write( "<p class=\"warning\">" +
			"This script only works in Internet Explorer 5.5" +
			" or greater for Windows</p>" );
	}
}
cssFile = "style/popmenu.css";

//<![CDATA[

// set css file to use for menus
Menu.prototype.cssFile = cssFile;

var tmp;

// Build context menu
var cMenu = new Menu();

var openItem, openNewWinItem;

cMenu.add( openItem = new MenuItem( "打开" ) );
openItem.mnemonic = "o";
cMenu.add( openNewWinItem = new MenuItem( "在新窗口打开" ) );
openNewWinItem.mnemonic = "n";
openNewWinItem.target = "_blank";	// open in new window





var backItem, forwardItem, refreshItem;


cMenu.add( backItem = new MenuItem( "后退", function () { window.history.go(-1); }, "images/icon/back.gif" ) );
backItem.mnemonic = "b";
cMenu.add( forwardItem = new MenuItem( "前进", function () { window.history.go(1); }, "images/icon/forward.gif" ) );
forwardItem.mnemonic = "o";
cMenu.add( refreshItem = new MenuItem( "刷新菜单", function () { document.location.reload(); }, "images/icon/icon-refresh.gif" ) );
refreshItem.mnemonic = "r";
cMenu.add( new MenuSeparator() );

cMenu.add( tmp = new MenuItem( "全部收缩", function(){collapseAll();}, "images/icon/shousuo.gif" ) );
cMenu.add( tmp = new MenuItem( "全部展开", function (){showAll(); }, "images/icon/zhankai.gif") );






var oldOpenState = null;	// used to only change when needed
var lastKeyCode = 0;

function rememberKeyCode() {
	lastKeyCode = window.event.keyCode;
}

function showContextMenu() {

	var el = window.event.srcElement;

	// check for edit
	var showEditMenu = el != null &&
						(el.tagName == "INPUT" || el.tagName == "TEXTAREA");

	// check for anchor
	while ( el != null && el.tagName != "A" )
		el = el.parentNode;

	var showOpenItems = el != null && el.tagName == "A";

	if ( showOpenItems != oldOpenState ) {
		openItem.visible		= showOpenItems;
		openNewWinItem.visible	= showOpenItems;
		backItem.visible		= !showOpenItems;
		forwardItem.visible		= !showOpenItems;
		refreshItem.visible		= !showOpenItems;
		oldOpenState = showOpenItems;
	}

	if ( showOpenItems ) {
		openItem.action = openNewWinItem.action = el.href;
	}

	// find left and top
	var left, top;

	if ( showEditMenu )
		el = window.event.srcElement;
	else if ( !showOpenItems )
		el = document.documentElement;

	if ( lastKeyCode == 93 ) {	// context menu key
		left = posLib.getScreenLeft( el );
		top = posLib.getScreenTop( el );
	}
	else {
		left = window.event.screenX;
		top = window.event.screenY;
	}

	//if ( showEditMenu ) {

		// undo is broken in IE
		// undoItem.disabled =			!document.queryCommandEnabled( "Undo" );
	//	cutItem.disabled =			!document.queryCommandEnabled( "Cut" );
	//	copyItem.disabled =			!document.queryCommandEnabled( "Copy" );
	//	pasteItem.disabled =		!document.queryCommandEnabled( "Paste" );
	//	deleteItem.disabled =		!document.queryCommandEnabled( "Delete" );
	//	selectAllItem.disabled =	!document.queryCommandEnabled( "SelectAll" );

	//	eMenu.invalidate();
	//	eMenu.show( left, top );
//	}
	//else {
		cMenu.invalidate();
		cMenu.show( left, top );
	//}

	event.returnValue = false;
	lastKeyCode = 0
};

document.attachEvent( "oncontextmenu", showContextMenu );
document.attachEvent( "onkeyup", rememberKeyCode );

//]]>